package com.example.elm.StoreAndGoods

import android.content.Intent
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.example.elm.Public.GoodsInfo
import com.example.elm.R
import com.example.elm.databinding.GoodsBinding

class GoodsActivity : ComponentActivity() {
    private lateinit var binding: GoodsBinding
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = GoodsBinding.inflate(layoutInflater)
        setContentView(binding.root)

        //获取数据
        val GoodData = intent.getSerializableExtra("good_data") as GoodsInfo
        //填充数据
        binding.a1.text = GoodData.name
        binding.a2.text = GoodData.comment
        binding.a3.text = GoodData.info
        binding.a5.text = "￥"+"${GoodData.price}"
        val imageResid = this.resources.getIdentifier(
            GoodData.image,"drawable",this.packageName
        )
        if (imageResid != 0) {
            binding.a4.setImageResource(imageResid)
        } else {
            binding.a4.setImageResource(R.drawable.aa1)
        }

        binding.fanhui.setOnClickListener{
            finish()
        }
        binding.gouwuche.setOnClickListener{
            val intent = Intent(this,GoodsChooseActivity::class.java)
            intent.putExtra("good_data", GoodData)
            startActivity(intent)
        }
    }
}